<template>
    <div>
        <span class="headerTitle">{{ route.query.title }}</span>
        <el-divider border-style="dashed" />
        <div class="testTitle" v-if="singleChoice.length>0"><span class="icon"></span><span class="label">单选题</span></div>
        <ul>
            <li v-for="item, index in singleChoice">
                <p class="testName">{{ index + 1 }}. {{ item.questionName }}</p>
                <el-radio-group v-model="item.userAnswer" class="shuStyle" disabled>
                    <el-radio label="A" v-if="item.A"><span class="value"> A. {{ item.A }}</span></el-radio>
                    <el-radio label="B" v-if="item.B"><span class="value"> B. {{ item.B }}</span></el-radio>
                    <el-radio label="C" v-if="item.C"><span class="value"> C. {{ item.C }}</span></el-radio>
                    <el-radio label="D" v-if="item.D"><span class="value"> D. {{ item.D }}</span></el-radio>
                    <el-radio label="E" v-if="item.E"><span class="value"> E. {{ item.E }}</span></el-radio>
                    <el-radio label="F" v-if="item.F"><span class="value"> F. {{ item.F }}</span></el-radio>
                </el-radio-group>
                <p :class="item.correct=='0'?'green':'red'"><span>您的答案：{{ item.userAnswer }}</span><span style="margin-left: 150px;">正确答案：{{ item.answers }}</span></p>
            </li>
        </ul>
        <div class="testTitle" v-if="multipleSelection.length>0"><span class="icon"></span><span class="label">多选题</span></div>
        <ul>
            <li v-for="item, index in multipleSelection">
                <p class="testName">{{ index + 1 }}. {{ item.questionName }}</p>
                <el-checkbox-group v-model="item.userAnswer" class="shuStyle" disabled>
                    <el-checkbox label="A" v-if="item.A"><span class="value"> A. {{ item.A }}</span></el-checkbox>
                    <el-checkbox label="B" v-if="item.B"><span class="value"> B. {{ item.B }}</span></el-checkbox>
                    <el-checkbox label="C" v-if="item.C"><span class="value"> C. {{ item.C }}</span></el-checkbox>
                    <el-checkbox label="D" v-if="item.D"><span class="value"> D. {{ item.D }}</span></el-checkbox>
                    <el-checkbox label="E" v-if="item.E"><span class="value"> E. {{ item.E }}</span></el-checkbox>
                    <el-checkbox label="F" v-if="item.F"><span class="value"> F. {{ item.F }}</span></el-checkbox>
                </el-checkbox-group>
                <p :class="item.correct=='0'?'green':'red'"><span>您的答案：{{ item.userAnswer.join(',') }}</span><span style="margin-left: 150px;">正确答案：{{ item.answers }}</span></p>
            </li>
        </ul>
        <div class="testTitle" v-if="judgment.length>0"><span class="icon"></span><span class="label">判断题</span></div>
        <ul>
            <li v-for="item, index in judgment">
                <p class="testName">{{ index + 1 }}. {{ item.questionName }}</p>
                <el-radio-group v-model="item.userAnswer" class="shuStyle" disabled>
                    <el-radio label="A" v-if="item.A"><span class="value"> A. {{ item.A }}</span></el-radio>
                    <el-radio label="B" v-if="item.B"><span class="value"> B. {{ item.B }}</span></el-radio>
                </el-radio-group>
                <p :class="item.correct=='0'?'green':'red'"><span>您的答案：{{ item.userAnswer }}</span><span style="margin-left: 150px;">正确答案：{{ item.answers }}</span></p>
            </li>
        </ul>
    </div>
</template>

<script setup name="checkAnswer">
import { getHistoryTest } from '@/api/knowledgeLearn/online/practiceInClass.js'

const route = useRoute();
const singleChoice = ref([]); // 单选
const multipleSelection = ref([]); // 多选
const judgment = ref([]); // 判断

// 获取题目
function getHistory() {
    getHistoryTest(route.query).then(res => {
        singleChoice.value = res.data.singleChoice ? res.data.singleChoice : [];
        if(res.data.multipleSelection){
            multipleSelection.value = res.data.multipleSelection;
            multipleSelection.value.forEach(item=>{
                item.userAnswer = item.userAnswer.split(',')
            })
        }else{
            multipleSelection.value = [];
        }
        judgment.value = res.data.judgment ? res.data.judgment : [];
    })
}

onMounted(() => {
    getHistory();
})
</script>

<style scoped lang="scss">
.headerTitle {
    display: inline-block;
    height: 100px;
    line-height: 100px;
    font-weight: bold;
    font-size: 30px;
    color: #333;
}

:deep(.el-divider) {
    margin: 0px;
}

.testTitle {
    margin: 30px 0px;
    height: 24px;
    display: flex;
    align-items: center;
    flex-direction: row;
    color: #107ce5;

    .icon {
        display: inline-block;
        width: 5px;
        height: 25px;
        background-color: #107ce5;
    }

    .label {
        font-size: 24px;
        font-weight: bold;
        margin-left: 10px;
    }
}

ul {
    list-style-type: none;
    margin: 0px !important;
    padding-left: 0px !important;

    li {
        margin-bottom: 28px;

        p {
            margin: 0px !important;
        }

        .shuStyle {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            margin-left: 30px;
        }

        .value {
            font-size: 20px;
            font-weight: 400;
            letter-spacing: 1.2;
        }

        .testName {
            font-weight: bold;
            font-size: 20px;
            margin-bottom: 12px !important;
        }
    }
}

.submit {
    display: inline-block;
    width: 150px;
    height: 50px;
    line-height: 50px;
    background: #107ce5;
    border: 1px solid #707070;
    border-radius: 4px;
    opacity: 1;
    color: #fff;
    font-size: 20px;
    font-weight: 400;
    cursor: pointer;
}

:deep(.el-dialog) {
    :deep(.el-dialog__body) {
        padding: 0 20px !important;
    }
}

.bgImg {
    width: 275px;
    height: 241px;
    border-radius: 0px;
    opacity: 1;
    background-color: yellowgreen;

    margin: 0 auto;
    text-align: center;

}

.score {
    color: #e34b00;
    font-weight: bold;
    font-size: 56px;
    position: relative;
    top: 50px;

}

.button {
    display: inline-block;
    text-align: center;
    line-height: 50px;
    width: 180px;
    height: 50px;
    border: 1px solid #999;
    border-radius: 25px;
    opacity: 1;
    color: #666666;
    font-size: 24px;
    margin: 10px;
    cursor: pointer;
}

.yellowColor {
    background-image: linear-gradient(to right, #be9c5e, #ad8437);
    color: #fff;
}
.green{
   color: #67C23A;
   font-size: 20px;
   margin-top: 10px!important;
   margin-left: 30px!important;
}
.red{
   color: #F56C6C;
   font-size: 20px;
   margin-top: 10px!important;
   margin-left: 30px!important;
}
</style>